﻿<?php // no direct access
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.view');

// montre la carte du voisinage
class amapViewcarte extends JView
{	
  var $amap;

  function display($tpl = null)
  {

    global $mainframe;
    $document =& JFactory::getDocument();
    $pathway  =& $mainframe->getPathway();
	
	// Adds parameter handling
	$params = $mainframe->getParams();

	$params->def( 'show_page_title', 1 );
	$params->def( 'page_title', 'Carte du voisinage');

	if ($this->amap->adLoggue){
	  if ($this->amap->adExiste && ($this->amap->adherent["PublicationAdresse"]==1)){
	    echo "<div class='amap_bloc'>";
	    echo "<h3 class='amap_titre'>Carte du voisinage</h3>";

	    //$data = $this->amap->getprodistri();

	    echo '<div id="mapdiv" style="height:600px;width:600px;align:center"></div>';
	    echo '<script src="http://www.openlayers.org/api/OpenLayers.js"></script>';
	    echo "<script>\n";
	    echo "map = new OpenLayers.Map('mapdiv');\n";
	    echo "map.addLayer(new OpenLayers.Layer.OSM());\n";
	    
	    echo "var seb = new OpenLayers.LonLat( 2.40101 , 48.87294 )\n";
	    echo "   .transform(\n";
            echo "   new OpenLayers.Projection('EPSG:4326'),\n"; // transform from WGS 1984"
            echo "   map.getProjectionObject()\n"; // to Spherical Mercator Projection
	    echo ");\n\n";

	    echo "var markers = new OpenLayers.Layer.Markers( 'Markers' );\n";
	    echo "map.addLayer(markers);\n";


	    echo "function contact(lon, lat, nom, adresse, email, tel)\n";
	    echo "{\n";
	    echo "var point = new OpenLayers.LonLat( lon , lat )\n";
	    echo "      .transform(\n";
	    echo "        new OpenLayers.Projection('EPSG:4326'),\n";
	    echo "        map.getProjectionObject() \n";
	    echo "      );\n";

	    echo "var marker = new OpenLayers.Marker(point);\n";
	    echo "markers.addMarker(marker);\n";
	    echo "marker.events.register('click', marker, function(e){\n";
	    
	    echo "popup = new OpenLayers.Popup.FramedCloud('adherent',\n";
	    echo "marker.lonlat,\n";
	    echo "new OpenLayers.Size(200, 200),\n";
	    echo "'<h3>'+nom+'</h3>'+'<br>'+adresse+'<br>'+tel+'<br>'+email,\n";
	    echo "null, true);\n";

	    echo "map.addPopup(popup);\n";
	    echo "}); \n";
	    echo "}\n";

	    foreach($this->amap->getVoisinageInfo() as $i)
	      {
		echo "contact(".$i["lon"].",".$i["lat"].",";
		echo "'".$i["Prenom"]." ".$i["Nom"]."',";
		echo "'".$i["Adresse"]."',";
		echo "'".$i["Email"]."',";
		echo "'".$i["Fixe"]." ".$i["Mobile"]."'";
		echo ");\n";
}
	    

	    

	    echo "var center = new OpenLayers.LonLat(2.40101, 48.87294  )\n";
	    echo "      .transform(\n";
	    echo "        new OpenLayers.Projection('EPSG:4326'),\n"; // transform from WGS 1984
	    echo "        map.getProjectionObject()\n"; // to Spherical Mercator Projection
	    echo "      );\n";
	    echo "var zoom=17;\n";
	    echo "map.setCenter (center, zoom);  \n";

	    echo "</script>\n";
	    echo "</div>";

	  parent::display($tpl);
	  }
	  else // n'a pas autorisé la publication d'adresse
	    {
	      echo "<div class='amap_bloc'>";
	      echo "<h3 class='amap_titre'>Carte du voisinage</h3>";
	      echo "<p>Vous n'avez pas autorisé la publication des informations de voisinage, vous n'avez pas accès à la carte du Voisinage.</p>";
	      echo "<p>Pour modifier votre fiche, aller dans <a href='index.php?option=com_amap&view=advoir'>Mon Compte</a>. </p>";
	      echo "</div>";

	    }
	}
  }
}  
?>

